package com.dormitory.javadormitory.mapper;

import com.dormitory.javadormitory.entity.ChangePasswordDTO;
import com.dormitory.javadormitory.entity.UserAccount;

import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;
import tk.mybatis.mapper.common.Mapper;

import java.util.List;

@Repository
public interface UserAccountMapper extends Mapper<UserAccount> {
//    int deleteByPrimaryKey(Integer userId);
//
//    int insert(UserAccount record);
//
//    UserAccount selectByPrimaryKey(Integer userId);
//
//    List<UserAccount> selectAll();
//
//    int updateByPrimaryKey(UserAccount record);

    @Select("SELECT * FROM useraccounts WHERE username=#{username} limit 1")
    UserAccount findByUsername(@Param("username") String username);


    @Insert("INSERT INTO useraccounts(username, password, email, role_id) VALUES (#{username}, #{password}, #{email}, #{roleId})")
    @Options(useGeneratedKeys = true, keyProperty = "userId")
    int addUserAccount(UserAccount userAccount);


    @Select("select * FROM useraccounts WHERE user_id = #{userId}")
    UserAccount findUserAccountByUserId(@Param("userId") Integer userId);

    @Select("SELECT * FROM useraccounts")
    List<UserAccount> allUserAccount();

    @Update("UPDATE useraccounts SET `password`=#{confirmPwd} WHERE user_id=#{userId}")
    void updateUserPwdByUserId(@Param("confirmPwd") String confirmPwd, @Param("userId") String userId);
}